package main

func main() {
	println(licenseKeyFormatting("2-5g-3-J", 2))
}

func licenseKeyFormatting(s string, k int) string {
	tmp := make([]uint8, 0)
	for i := range s {
		if s[i] != '-' {
			if 'a' <= s[i] && s[i] <= 'z' {
				tmp = append(tmp, s[i]-32)
				continue
			}
			tmp = append(tmp, s[i])
		}
	}
	count := len(tmp)
	first := count % k

	if count == 1 || count == 0 {
		return string(tmp)
	}

	for i := 0; ; i++ {
		if first != 0 {
			i += first
			tmp = append(tmp[:first], append([]uint8{'-'}, tmp[first:]...)...)
			first = 0
			continue
		}
		i += k
		if i == len(tmp) {
			break
		}
		tmp = append(tmp[:i], append([]uint8{'-'}, tmp[i:]...)...)
	}
	return string(tmp)
}
